﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using KBEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class hallPanel : MonoBehaviour
{
    Account account;
    Transform topRoot;
    Text playernameText;
    Text playeridText;

    // Use this for initialization
    void Start ()
    {
        if (KBEngineApp.app == null)
        {
            GameManager.GetInstance().showMessagePanel("已和服务器断开连接！", () =>
            {
                //Application.LoadLevel("login");
                SceneManager.LoadScene("login");
            });
            return;
        }

        account = (Account)KBEngineApp.app.player();
        if (account == null)
        {
            GameManager.GetInstance().showMessagePanel("已和服务器断开连接！", () =>
            {
                //Application.LoadLevel("login");
                SceneManager.LoadScene("login");
            });
        }

        Init();
        InitCharInfo();
    }

    //初始化UI组件
    private void Init()
    {
        topRoot = transform.Find("top");
        playernameText = topRoot.Find("playername").GetComponent<Text>();
        playeridText = topRoot.Find("playerid").GetComponent<Text>();
    }
	
	//初始化角色信息
    private void InitCharInfo()
    {
        playernameText.text = account.CharName_base;
        playeridText.text = "ID:" + account.CharId_base.ToString();
    }
}
